package com.lixuwei.study.tcc.order.web;

import com.lixuwei.study.tcc.order.entity.Order;
import com.lixuwei.study.tcc.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;


    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ResponseBody
    public String getInfo() {
        return "order service";
    }

    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    @ResponseBody
    public String createOrder() {
        Order order = new Order();
        order.setBuyerId(1L);
        order.setShopId(1);
        order.setPrice(100L);
        orderService.createOrder(order);
        return "order id " + order.getId();
    }

    @RequestMapping(value = "/payOrder", method = RequestMethod.POST)
    @ResponseBody
    public String payOrder(@RequestParam("orderId") Long orderId) {
        orderService.payOrderByPoints(orderId);
        return "order id " ;
    }
}
